// import getServer, { Server } from '@/api/server/getServer';


import { create } from 'zustand'
import { immer } from "zustand/middleware/immer"

// import { action, Action, computed, Computed, createContextStore, thunk, Thunk } from 'easy-peasy';
import * as socket from './socket';

export type ServerStatus = 'offline' | 'starting' | 'stopping' | 'running' | null;

// interface ServerDataStore {
//     data?: Server;
//     inConflictState: Computed<ServerDataStore, boolean>;
//     isInstalling: Computed<ServerDataStore, boolean>;
//     permissions: string[];

//     getServer: Thunk<ServerDataStore, string, Record<string, unknown>, ServerStore, Promise<void>>;
//     setServer: Action<ServerDataStore, Server>;
//     setServerFromState: Action<ServerDataStore, (s: Server) => Server>;
//     setPermissions: Action<ServerDataStore, string[]>;
// }

// const server: ServerDataStore = {
//     permissions: [],

//     inConflictState: computed((state) => {
//         if (!state.data) {
//             return false;
//         }

//         return state.data.status !== null || state.data.isTransferring || state.data.isNodeUnderMaintenance;
//     }),

//     isInstalling: computed((state) => {
//         return state.data?.status === 'installing' || state.data?.status === 'install_failed';
//     }),

//     getServer: thunk(async (actions, payload) => {
//         const [server, permissions] = await getServer(payload);

//         actions.setServer(server);
//         actions.setPermissions(permissions);
//     }),

//     setServer: action((state, payload) => {
//         if (!isEqual(payload, state.data)) {
//             state.data = payload;
//         }
//     }),

//     setServerFromState: action((state, payload) => {
//         const output = payload(state.data!);
//         if (!isEqual(output, state.data)) {
//             state.data = output;
//         }
//     }),

//     setPermissions: action((state, payload) => {
//         if (!isEqual(payload, state.permissions)) {
//             state.permissions = payload;
//         }
//     }),
// };

// interface ServerStatusStore {
//     value: ServerStatus;
//     setServerStatus: Action<ServerStatusStore, ServerStatus>;
// }

// const status: ServerStatusStore = {
//     value: null,
//     setServerStatus: action((state, payload) => {
//         state.value = payload;
//     }),
// };

// export interface ServerStore {
//     server: ServerDataStore;
//     subusers: ServerSubuserStore;
//     databases: ServerDatabaseStore;
//     files: ServerFileStore;
//     schedules: ServerScheduleStore;
//     socket: SocketStore;
//     status: ServerStatusStore;
//     taskList: TaskListStore;
//     extraButtons: { [key: string]: { key: string; name: string; onClick: () => void } };
//     extraRoutes: { [key: string]: ExtraRoute };
//     addExtraButton: Action<
//         ServerStore,
//         { key: string; name: string; onClick: () => void } | { key: string; name: string; onClick: () => void }[]
//     >;
//     clearServerState: Action<ServerStore>;
// }

export const ServerContext = {
    socket,
    server: {
        permissions: []
    } as any
}